﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace AI.Steering
{
    /// <summary>
    /// 分散
    /// </summary>
    public class SteeringForDisperse : Steering
    {
        [Tooltip("最大间隔")]
        public float maxDistance = 5;
        private Radar radar;
        private void Start()
        {
            radar = GetComponent<Radar>();
        }
        public override Vector3 GetForce()
        {
            Vector3 expectForce = Vector3.zero;
            for (int i = 0; i < radar.targetList.Count; i++)
            {
                if (Vector3.Distance(transform.position,radar.targetList[i].position) > maxDistance)
                {
                    continue;
                }
                //期望力：
                //累加目标物体 到 当期物体的排斥力
                expectForce += (transform.position - radar.targetList[i].position).normalized * speed;
            }
            //返回实际力
            if (expectForce == Vector3.zero)
            {
                return Vector3.zero;
            }
            return (expectForce - controller.currentForce) * weight;
        }
    }
}

